<template>
	<!-- 评价弹窗 -->
	<u-popup v-model="isShow" mode="bottom" :border-radius="36" :closeable="true">
		<view class="bottomSheet_content">
			<view class="title">评价</view>
			<view class="first_area">
				<view class="flex_row line">
					<view class="label">专业度</view>
					<u-rate :count="5" v-model="form.majorScore" active-color="#FFCC0B" size="41" gutter="10" />
				</view>
				<view class="flex_row line">
					<view class="label">服务态度</view>
					<u-rate :count="5" v-model="form.attitudeScore" active-color="#FFCC0B" size="41" gutter="10" />
				</view>
				<view class="flex_row line">
					<view class="label">响应速度</view>
					<u-rate :count="5" v-model="form.responseScore" active-color="#FFCC0B" size="41" gutter="10" />
				</view>
			</view>
			<view class="list" v-if="tagsData.length > 0">
				<view :class="{'offTag': showTag === false }" class="flex_wrap">
					<u-tag :text="row.value" type="info" shape="circle" :mode="row.selected === false ? 'plain' : 'dark'" :key="index" v-for="(row,index) in tagsData" style="margin-right: 12upx;margin-bottom: 10upx;" @tap="selectTag(index)"/>
				</view>
				<view style="width: 46upx;" :style="{ transform:(showTag == true?'rotate(180deg)':'rotate(0deg)') }" @tap="showNav">
					<image src="/static/img/select.png" mode="aspectFit" style="width: 46upx;height: 46upx;"></image>
				</view>
			</view>
			<view class="bottom_area">
				<view>评价</view>
				<view class="textarea">
					<textarea :value="form.content" placeholder="请输入你想说的..." placeholder-style="fontsize: 20upx;color: #666666;font-weight: 400" style="padding: 5upx;width: 100%;height: 153upx;" @input="inputText"/>
				</view>
			</view>
			<view class="mocup_btn lgbtn" @tap="$u.throttle(select, 500)">
				提交
			</view>
		</view>
	</u-popup>
</template>

<script>
	import { isBlank } from '@/utils/common.js'
	
	export default {
		name: 'orderPopue',
		// 父组件传入的props参数
		props: ['orderData'],
		data() {
			return {
				isShow: false,
				showTag: false,
				tagsData: [],
				form: {
					attitudeScore: 0,
					majorScore: 0,
					responseScore: 0,
					content: "",
					tags: '',
				},
			};
		},
		created(){
			this.fetchTagsData()
		},
		methods: {
			// 调用show方法展示
			show() {
				this.showTag = false,
				this.isShow = true;
				this.form = {
					attitudeScore: 0,
					majorScore: 0,
					responseScore: 0,
					content: "",
					tags: '',
				}
				for(let i in this.tagsData) {
					this.tagsData[i].selected = false
				}
			},
			// 消失后移除自身所占资源
			hide() {
				this.isShow = false;
			},
			// 获取标签数据
			fetchTagsData() {
				var data = {
					dicType: "comment_tag"
				}
				this.$u.api.findDicByType(data).then(res => {
					if (res.code === 200) {
						this.tagsData = res.data
						for(let i in this.tagsData) {
							this.tagsData[i].selected = false
						}
					}
				})
			},
			showNav() {
				this.showTag = !this.showTag;
			},
			selectTag(index) {
				let list = []
				this.tagsData[index].selected = !this.tagsData[index].selected
				for(let i in this.tagsData) {
					if(this.tagsData[i].selected === true) {
						list.push(this.tagsData[i].value)
					} 
				}
				this.form.tags = JSON.stringify(list)
			},
			inputText(e) {
				this.form.content = e.detail.value
			},
			select(val) {	
				this.form.orderId = this.orderData.id
				this.form.userId = this.orderData.stylist.id
				
				this.$u.api.addComment(this.form).then(res => {
					if (res.code === 200) {
						uni.showToast({
							title: "评价成功"
						});
						this.hide()
					}
				})
				// this.$emit('commentOrder', data); //select事件触发后，自动触发showCityName事件  
			}
		}
	}
</script>

<style lang="scss">
	.bottomSheet_content {
		margin: 28rpx 30rpx;
		display: flex;
		flex-direction: column;
		// min-height: 663upx;

		.title {
			font-size: 36upx;
			font-weight: bold;
			color: #333333;
			margin-top: 10upx;
			text-align: center;
		}
		
		.first_area {
			margin-top: 10upx;
			.line {
				margin: 20upx 0;
			}
			.label {
				font-size: 32upx;
				font-weight: 500;
				color: #333333;
				text-align: left;
				width: 200upx;
			}
		}
		
		.list {
			margin-top: 20upx;
			margin-bottom: 36upx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			
			// 关闭标签栏
			.offTag {
				overflow: hidden;
				height: 50upx;
			}
		
			.box {
				padding: 8upx 28upx 8upx 28upx;
				border-radius: 24upx;
				border: 1px solid #1C1724;
				margin-right: 24upx;
				margin-bottom: 5upx;
				display: inline-block;
		
				.img {
					width: 100%;
					display: flex;
					justify-content: center;
		
					.icon {
						font-size: 50upx;
						color: #464646;
					}
				}
		
				.text {
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 28upx;
					color: #3d3d3d;
				}
			}
		
			.box_black {
				padding: 8upx 32upx 8upx 32upx;
				border-radius: 24upx;
				border: none;
				margin-right: 24upx;
				margin-bottom: 5upx;
				background: #48454D;
				display: inline-block;
		
				.text {
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 28upx;
					color: white;
				}
			}
		}
		
		.bottom_area {
			font-size: 32upx;
			font-weight: 500;
			color: #333333;
			display: flex;
			flex-direction: row;
			align-items: flex-start;
			justify-content: space-between;
			.textarea {
				height: 153upx;
				width: 594upx;
				border: 1px solid #d8d8d8;
				background: #FFFFFF;
			}
		}
		
		.lgbtn {
			margin: 30upx auto;
			width: 252upx;
			height: 90upx;
		}
	}
</style>
